package com.DreamTeam.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.DreamTeam.dao.IStatisticalDao;

public class StatisticalDao implements IStatisticalDao {
	private Connection conn = null;

	public StatisticalDao(Connection conn) {
		this.conn = conn;
	}
	
	@Override
	public boolean autoUpdateOrderSum() {
		String sql = "UPDATE orderMaster SET OrderSum=(select sum(Qty*OrderPrice) from "
				+ "orderDetail where orderMaster.OrderNo=orderDetail.OrderNo)";
		PreparedStatement prsmt = null;
		int flag = 0;
		try {
			prsmt = conn.prepareStatement(sql);
			flag = prsmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		if (flag > 0)
			return true;
		else
			return false;
	}

}
